package com.wondersgroup.wuhan_demo.base;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.wondersgroup.wuhan_demo.R;
import com.wondersgroup.wuhan_demo.ui.DeptSelectFragment;
import com.wondersgroup.wuhan_demo.ui.DoctorSelectFragment;
import com.wondersgroup.wuhan_demo.util.OnSingleClickListener;

/**
 * Created by liyaqing on 2018/5/7 0007.
 */


public class BaseActivity extends AppCompatActivity {
    private final int BACK = 0x125;
    public Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case BACK:
                    finish();
                    break;
            }
        }
    };
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        handler.sendEmptyMessageDelayed(BACK,30*1000);
    }

    protected void initTitleBar(@NonNull String title) {
//        ImageView ivBack = (ImageView) findViewById(R.id.iv_back);
//        ivBack.setOnClickListener(new OnSingleClickListener() {
//            @Override
//            public void onSingleClick(View v) {
//                finish();
//            }
//        });
        TextView tvTitle = (TextView) findViewById(R.id.tv_title);
        tvTitle.setText(title);
    }

    protected void toast(final String msg) {
        Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show();
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {

        if (ev.getAction()==MotionEvent.ACTION_DOWN) {
            Log.i("event==","dispatchTouchEvent");
            handler.removeCallbacksAndMessages(null);
            handler.sendEmptyMessageDelayed(BACK, 30 * 1000);
        }
        return super.dispatchTouchEvent(ev);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        handler.removeCallbacksAndMessages(null);
    }
    //    @Override
//    public boolean onTouchEvent(MotionEvent event) {
//        Log.i("event==","event");
////        tochTime = (String) SPUtils.get(MyApplication.getContextObject(),"tochTime","");
////        SPUtils.put(MyApplication.getContextObject(),"tochTime", DataUtil.ConverToString(new Date()));
////        if (!TextUtils.isEmpty(tochTime)){
////
////        }
//        handler.removeCallbacksAndMessages(null);
//        handler.sendEmptyMessageDelayed(BACK,30*1000);
//        return super.onTouchEvent(event);
//    }

}
